#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 crane <crane@gosun>
#
# Distributed under terms of the MIT license.

"""

"""

import math

# ∑:
def sigma(start, end, fn):
    return sum( [fn(i) for i in range(start, end)] )

def comb(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

def half_suc(p, n):
    # 三局两胜, 五局三胜
    total = 2 * n + 1
    q = 1 - p
    fn = lambda t : (p ** t ) * (q ** (total-t)) * comb(total, t)
    return sigma(n+1, total+1,  fn)

def main():
    print("start main")
    # v = sigma(8, 10, lambda x : x*x)
    # print(v)
    v = half_suc(0.6, 3)
    print(v)

if __name__ == "__main__":
    main()
